package com.gpjcjl.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.gpjcjl.R;
import com.gpjcjl.entity.Produce;
import com.gpjcjl.entity.SettingProfile;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * 制造单位适配器
 *
 * @author yinbiao
 * @date 2020-10-26 09:28:37
 */
public class ProduceAdapter extends BaseRecyclerAdapter<Produce> {

    public ProduceAdapter(Context context, List<Produce> datas) {
        super(context, R.layout.item_company, datas);
    }

    @Override
    protected void convert(ViewHolder holder, Produce produce, int position) {
        String num = produce.getProduce_num();
        int index = num.indexOf("-");
        if (index >= 5) {
            num = num.substring(index - 5, index);
        }
        holder.setText(R.id.tv, produce.getProduce() + num);
        holder.setVisible(R.id.iv, produce.getProduce().equals(SettingProfile.getProduce()));
    }

    public void filter(String keywords) {
        for (int i = mDatas.size() - 1; i >= 0; i--) {
            String num = mDatas.get(i).getProduce_num();
            int index = num.indexOf("-");
            if (index >= 5) {
                num = num.substring(index - 5, index);
            }
            String name = mDatas.get(i).getProduce() + num;
            if (TextUtils.isEmpty(name) || !name.contains(keywords)) {
                mDatas.remove(i);
            }
        }
        notifyDataSetChanged();
    }
}

